package sf.r2dbc.connection;

import io.r2dbc.spi.Batch;
import io.r2dbc.spi.Connection;
import io.r2dbc.spi.ConnectionFactory;
import io.r2dbc.spi.ConnectionMetadata;
import io.r2dbc.spi.IsolationLevel;
import io.r2dbc.spi.Statement;
import io.r2dbc.spi.ValidationDepth;
import org.reactivestreams.Publisher;
import sf.database.dao.DBContext;
import sf.database.dialect.DBDialect;
import sf.r2dbc.sql.R2dbcContext;
import sf.spring.util.Assert;

import java.time.Duration;

public class R2dbcConnection implements Connection {
    protected Connection connection;
    protected ConnectionFactory connectionFactory;
    protected DBDialect dbDialect;
    protected R2dbcContext r2dbcContext;
    protected DBContext dbContext;

    public R2dbcConnection(Connection connection, ConnectionFactory connectionFactory) {
        Assert.notNull(connection, "");
        Assert.notNull(connectionFactory, "");
        this.connection = connection;
        this.connectionFactory = connectionFactory;
    }

    public Publisher<Void> beginTransaction() {
        return connection.beginTransaction();
    }

    public Publisher<Void> close() {
        return connection.close();
    }

    public Publisher<Void> commitTransaction() {
        return connection.commitTransaction();
    }

    public Batch createBatch() {
        return connection.createBatch();
    }

    public Publisher<Void> createSavepoint(String name) {
        return connection.createSavepoint(name);
    }

    public Statement createStatement(String sql) {
        return connection.createStatement(sql);
    }

    public boolean isAutoCommit() {
        return connection.isAutoCommit();
    }

    public ConnectionMetadata getMetadata() {
        return connection.getMetadata();
    }

    public IsolationLevel getTransactionIsolationLevel() {
        return connection.getTransactionIsolationLevel();
    }

    public Publisher<Void> releaseSavepoint(String name) {
        return connection.releaseSavepoint(name);
    }

    public Publisher<Void> rollbackTransaction() {
        return connection.rollbackTransaction();
    }

    public Publisher<Void> rollbackTransactionToSavepoint(String name) {
        return connection.rollbackTransactionToSavepoint(name);
    }

    public Publisher<Void> setAutoCommit(boolean autoCommit) {
        return connection.setAutoCommit(autoCommit);
    }

    public Publisher<Void> setTransactionIsolationLevel(IsolationLevel isolationLevel) {
        return connection.setTransactionIsolationLevel(isolationLevel);
    }

    public Publisher<Boolean> validate(ValidationDepth depth) {
        return connection.validate(depth);
    }

    public Publisher<Void> beginTransaction(io.r2dbc.spi.TransactionDefinition transactionDefinition) {
        return connection.beginTransaction(transactionDefinition);
    }

    public Publisher<Void> setLockWaitTimeout(Duration duration) {
        return connection.setLockWaitTimeout(duration);
    }

    public Publisher<Void> setStatementTimeout(Duration duration) {
        return connection.setStatementTimeout(duration);
    }

    public Connection getConnection() {
        return connection;
    }

    public ConnectionFactory getConnectionFactory() {
        return connectionFactory;
    }

    public DBDialect getDbDialect() {
        return dbDialect;
    }

    public void setDbDialect(DBDialect dbDialect) {
        this.dbDialect = dbDialect;
    }

    public R2dbcContext getR2dbcContext() {
        return r2dbcContext;
    }

    public void setR2dbcContext(R2dbcContext r2dbcContext) {
        this.r2dbcContext = r2dbcContext;
    }

    public DBContext getDbContext() {
        return dbContext;
    }

    public void setDbContext(DBContext dbContext) {
        this.dbContext = dbContext;
    }
}
